<?php

class Upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
	}

	function index()
	{
		$this->load->view('upload_form', array('error' => ' ' ));
	}

	function do_upload()
	{
		$config['upload_path'] = 'appcode/upld';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '10000';
		$config['max_width']  = '10240';
		$config['max_height']  = '7680';

		$this->load->library('upload', $config);

		
		if ( ! $up=$this->upload->do_upload('file'))		
		{		
			$error = array('error' => $this->upload->display_errors());
			print_r($error);
			$this->load->view('upload_form', $error);
		}
		else
		{		
			$info=$this->upload->data();
			//print_r($info);
			//$data = array('upload_data' => $this->upload->data());
			//$this->load->view('upload_success', $data);
			
			//return json_encode( $this->upload->data();, JSON_FORCE_OBJECT);

			//{"status_code":200,"status_txt":"OK","data":{"img_name":"ynALc.png","img_url":"http:\/\/s0.uploads.im\/ynALc.png","img_view":"http:\/\/uploads.im\/ynALc.png","img_width":"16","img_height":"16","img_attr":"width=\"16\" height=\"16\"","img_size":"0.6 KB","img_bytes":624,"thumb_url":"http:\/\/s0.uploads.im\/t\/ynALc.png","thumb_width":360,"thumb_height":360,"source":"base64 image string","resized":"0","delete_key":"37cc79e36be16e48"}}			  
			  //﻿{"status_code":200                  ,"data":{"img_name":"ynALc.png","img_url":"http:\/\/s0.uploads.im\/ynALc.png"}}

			//$data=array("status_code"=>200,
			//			"status_txt"=>"OK",
			//			"data"=>array(
			//				"img_name"=>"favicon.png",
			//				"img_url"=>"http://localhost:8080/ci/appcode/upld/favicon.png",							
			//				"img_view"=>"http://localhost:8080/ci/appcode/upld/favicon.png",
			//				"img_width"=>"16",
			//				"img_height"=>"16",
			//				"img_attr"=>"width=\"16\" height=\"16\"",
			//				"img_size"=>"0.6 KB",
			//				"img_bytes"=>624,
			//				"thumb_url"=>"http://localhost:8080/ci/appcode/upld/favicon.png",
			//				"thumb_width"=>360,
			//				"thumb_height"=>360,
			//				"source"=>"base64 image string",
			//				"resized"=>"0",
			//				"delete_key"=>"37cc79e36be16e48"							
			//				));
						
	
			//$this->output
			// ->set_content_type('application/json;charset=UTF-8')
			//->set_output(json_encode($data));

			 header('Content-type: application/json');

		 //   [file_name] => favicon19.png
		 //   [file_type] => image/png
		 //   [file_path] => D:/Development/xamp/htdocs/ci/appcode/upld/
		 //   [full_path] => D:/Development/xamp/htdocs/ci/appcode/upld/favicon19.png
		 //   [raw_name] => favicon19
		 //   [orig_name] => favicon.png
		 //   [client_name] => favicon.png
		 //   [file_ext] => .png
		 //   [file_size] => 0.61
		 //   [is_image] => 1
		 //   [image_width] => 16
		 //   [image_height] => 16
		 //   [image_type] => png
		 //   [image_size_str] => width="16" height="16"


			$link = array("link" =>BASE_URL().'appcode/upld/'. $info['file_name']);
			echo json_encode($link);

		}
	}
}
